package com.szrt.day20170424.ch01;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;

/**
 * 如果需要把1个对象保存到硬盘中  需要实现一个接口
 * @author scott-13926583118
 * 2017年4月24日
 *
 */
public class Student implements Externalizable {


	private String name;
	
	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException {
		System.out.println("writeExternal");
		System.out.println(out.getClass());
		
		//依次写入值
		out.writeObject(name);
		out.writeObject(age);
		
	}

	@Override
	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
		System.out.println("readExternal");
		
		//依次拿出值
		this.name = (String)in.readObject();
		this.age = (Integer)in.readObject();
	}
	
	
	
	
}
